﻿using System;
using System.Linq;

class Program
{
    static int MaxElementInPortion(int[] array, int startPossition)
    {
        int bestElement = int.MinValue;
        int bestPossition = 0;

        for (int possition = startPossition; possition < array.Length; possition++)
        {
            if (bestElement < array[possition])
            {
                bestElement = array[possition];
                bestPossition = possition;

            }    
        }

        return bestPossition;
    }

    static int[] SortArray(int[] array, bool reverse)
    {
        
        for (int counter = 0; counter < array.Length; counter++)
        {
            int tempMaxElement =  array[MaxElementInPortion(array, counter)];
            array[MaxElementInPortion(array, counter)] = array[counter];
            array[counter] = tempMaxElement;
        }

        if (reverse)
        {
            return array;
        }
        else
        {
            Array.Reverse(array);
            
        }

        return array;
    }

    static void Main()
    {
        int[] myArray = { 1, 4, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 5, 5, 5, 6, 6, 7, 8 };

        Console.WriteLine(string.Join(", ",SortArray(myArray, false)));
    }
}
